import { AxiosRequestConfig } from 'axios';
import { useUserHttp } from '@/api/useHttp';
import {
  IForgotPasswordParam,
  ISendSmsParam,
  ISmsLoginParam,
  IUpdatePasswordParam,
  IUpdateUserinfoParam,
  IUserLoginParam,
  R,
} from '@/api/types';
import { IAuth, IUser } from '@/store/types';

export enum UserApi {
  sendSms = '/login/getSMSCode',
  smsLogin = '/login/mobile',
  userLogin = '/login/username',
  userinfo = '/user/getUserInfo',
  getCaptcha = '/captcha',
  updateUserinfo = '/user/updateUserInfo',
  updateAvatar = '/user/updateHeadImg',
  forgotPassword = '/user/forgetPwd',
  updatePassword = '/login/updatePwd',
}

export const reqUpdateAvatar = (param: FormData) => {
  return useUserHttp<R<null>>({ url: UserApi.updateAvatar, data: param, method: 'POST' });
};

export const reqSendSms = (param: ISendSmsParam) => {
  return useUserHttp<R<null>>({ url: UserApi.sendSms, data: param, method: 'POST' });
};

export const reqSmsLogin = (param: ISmsLoginParam) => {
  return useUserHttp<R<IAuth>>({ url: UserApi.smsLogin, data: param, method: 'POST' });
};

export const reqUserLogin = (param: IUserLoginParam) => {
  return useUserHttp<R<IAuth>>({ url: UserApi.userLogin, data: param, method: 'POST' });
};

export const reqUserinfo = () => {
  return useUserHttp<R<IUser>>({ url: UserApi.userinfo });
};

export const reqUpdateUserinfo = (param: IUpdateUserinfoParam) => {
  return useUserHttp<R<null>>({ url: UserApi.updateUserinfo, data: param, method: 'PUT' });
};

export const reqForgotPassword = (param: IForgotPasswordParam) => {
  return useUserHttp<R<null>>({ url: UserApi.forgotPassword, data: param, method: 'POST' });
};

export const reqUpdatePassword = (param: IUpdatePasswordParam) => {
  return useUserHttp<R<null>>({ url: UserApi.updatePassword, data: param, method: 'PUT' });
};
